Skip to content

Conversation

@JoeCap08055
Copy link
Collaborator

Goal

The goal of this PR is to migrate the messages pallet to add schema_id to message storage, and use intent_id as the index instead.

Existing index values do not need to be changed, as the schemas pallet migration ensures that the chain is seeded with Intent IDs that match existing Schema IDs

Related to #2581

Checklist

  • Updated Pallet Readme?
  • Updated js/api-augment for Custom RPC APIs?
  • Design doc(s) updated?
  • Unit Tests added?
  • e2e Tests added?
  • Benchmarks added?
  • Spec version incremented?

@codecov
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 78.59779% with 58 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pallets/messages/src/types.rs 54.43% 36 Missing ⚠️
common/primitives/src/messages.rs 0.00% 13 Missing ⚠️
common/primitives/src/cid.rs 92.68% 6 Missing ⚠️
pallets/messages/src/migration/v3.rs 97.26% 2 Missing ⚠️
pallets/messages/src/migration/v2/mod.rs 50.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
pallets/messages/src/lib.rs 91.72% <100.00%> (ø)
pallets/messages/src/rpc/src/lib.rs 96.07% <100.00%> (ø)
pallets/messages/src/migration/v2/mod.rs 50.00% <50.00%> (ø)
pallets/messages/src/migration/v3.rs 97.26% <97.26%> (ø)
common/primitives/src/cid.rs 92.68% <92.68%> (ø)
common/primitives/src/messages.rs 92.54% <0.00%> (ø)
pallets/messages/src/types.rs 58.06% <54.43%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Sep 30, 2025
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the following enhancements for try-runtime-* targets:

  • Only build the runtime, not the entire node; speeds up the build
  • Consolidate targets using patterns to avoid duplicated targets/commands
  • Fetch state for a minimal set of system pallets so that multi-block migrations can be properly tested
  • Allow the use of the PALLETS env var to specify additional pallets for dumping/restoring state

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert types here; need to remain compatible with existing custom RPC

Comment on lines -82 to -87
// Max payload size was picked specifically to be large enough to accommodate
// a CIDv1 using SHA2-256, but too small to accommodate CIDv1 w/SHA2-512.
// This is purely so that we can test the error condition. Real world configuration
// should have this set large enough to accommodate the largest possible CID.
// Take care when adding new tests for on-chain (not IPFS) messages that the payload
// is not too big.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an erroneous assumption. Since the configured value would never be this small on mainnet or testnet, it's better to allow a CIDv1/SHA2-512 by size, and have it fail for CID validation instead of for size reasons.

/// Helper function to generate message payloads
///
/// # Arguments
/// * `num_items` - Number of message to include in payload
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed overly complicated--a payload is just an array of bytes; why all the JSON stuff?

@github-actions github-actions bot removed metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Sep 30, 2025
Comment on lines 393 to 394
let cid = Cid::read_bytes(&cid_b[..]).map_err(|_| Error::<T>::InvalidCid)?;
ensure!([SHA2_256, BLAKE3].contains(&cid.hash().code()), Error::<T>::InvalidCid);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When cleaning up the mocks for the tests, noticed that it was attempting to test failure to accept CIDv1 (SHA2-512) by setting the max payload length artificially small.

The more correct approach (and what was missing from the code, eclipsed by that artificial test scenario) is to reject any CIDs with an unsupported hash. DSNP supports ONLY SHA2-256 and Blake3.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, I should do that in Provider Context as well

Copy link
Collaborator

@saraswatpuneet saraswatpuneet Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you like, would you like to make similar changes for cid validation for msa pallet, since this is an enhancement nevertheless, might refactor some?

@JoeCap08055 JoeCap08055 marked this pull request as ready for review September 30, 2025 20:06
@github-actions github-actions bot added metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Sep 30, 2025
@github-actions github-actions bot added metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented and removed metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Sep 30, 2025
@JoeCap08055 JoeCap08055 changed the title 2581 update messages and stateful storage pallets to support intents 2581 update messages pallet to support intents Oct 1, 2025

/// Storage for messages
#[pallet::storage]
pub(super) type MessagesV2<T: Config> = StorageNMap<
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might have to retain (if downstream consumers are tied to this state)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not be ideal; the number of keys is very large.
To my knowledge, this is only used in:

  • Gateway (content-watcher)
  • Possibly the Freesky content viewer tool that @wesbiggs built

I will file issues in both of these repos.

@github-actions github-actions bot removed metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Oct 2, 2025
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not really net-new; I just haven't merged from main in a while. I've added some additional consts, and moved the CID validation function and tests from the messages pallet.

@github-actions github-actions bot added metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented labels Oct 2, 2025
@JoeCap08055 JoeCap08055 merged commit 8a4ff8c into feat/schemas-permissions-development Oct 9, 2025
29 of 32 checks passed
@JoeCap08055 JoeCap08055 deleted the 2581-update-messages-and-stateful-storage-pallets-to-support-intents branch October 9, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metadata-changed Metadata has changed since the latest full release metadata-version-not-incremented Metadata has changed since the latest full release, but the version has not been incremented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants